#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <stdlib.h>
extern char** environ;
int main()
{
    pid_t id = fork();
    assert(id >= 0);
    if(id == 0)
    {
        printf("child running.....\n");
        //execl("/usr/bin/ls", "ls", "-a", "-l", "--color=auto", NULL);   
        //execlp("ls", "ls", "-a", "-l", "--color=auto", NULL);
        char* const argv[] = {
            (char*)"ls",
            (char*)"-a",
            (char*)"-l",
            (char*)"--color=auto",
            NULL 
        };
       //execv("/usr/bin/ls", argv);   
       //execvp("ls", argv);
       //execl("./mycpp", "mycpp", NULL);
        char* const envp[] = {
            (char*)"MYENV=73623672"
        };
        putenv("MYENV=1234567");
        execle("./mycpp", "mycpp", NULL, environ);
        _exit(10);
    }
    else if(id > 0) 
    {
        sleep(3);
        int status = 0;
        pid_t ret = waitpid(id, &status, 0);
        if(ret < 0)
        {
           printf("wait fail\n"); 
        }
        else if(ret > 0)
        {
            printf("wait success, child exit code : %d, child exit signal : %d\n", status >> 8 & 0xff, status & 0x7f);
        }
    }

    return 0;
}
